package com.tycmc.signelectroniccontracts.tools.other;

import android.text.InputFilter;
import android.text.Spanned;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by gaoyong on 2018/6/11.
 */

public class NoChinseValueFilter implements InputFilter {
    @Override
    public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
        if (isContainChinese(source + "")) {
            Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
            Matcher m = p.matcher(source + "");
            String all = m.replaceAll("");
            return all;
        }
        return source;

    }

    public boolean isContainChinese(String str) {


        Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
        Matcher m = p.matcher(str);
        if (m.find()) {
            return true;
        }
        return false;
    }
}
